using QxFramework.Core;
using UnityEngine.UI;
using UnityEngine;

public class HintUI : UIBase
{
    private Text text;
    private float counter;
    private float maxTime;

    private void Awake()
    {
        text = transform.Find("Text").GetComponent<Text>();
    }

    private void Update()
    {
        if (counter < 0)
        {
            UIManager.Instance.Close("HintUI");
        }
        else
        {
            GetComponent<CanvasGroup>().alpha = counter / maxTime > 1 ? 1 : counter / maxTime;
            counter -= Time.unscaledDeltaTime;
        }
    }

    public void Show(string content, float time = 2)
    {
        text.text = content;
        counter = time + 1;
        maxTime = time;
    }
}
